package cn.com.winning.ecare.common;

import java.util.ArrayList;
import java.util.List;

import android.content.Context;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.TextView;
import cn.com.winning.ecare.activity.R;
import cn.com.winning.ecare.model.Node;

/**
 * 自定义listview布局显示内容
 * 
 * @author zjj
 * 
 */
public class MyCommPopupWindowAdapter extends BaseAdapter {
	private Context con;
	private LayoutInflater mInflater;
	private List<Node> list = new ArrayList<Node>();

	public MyCommPopupWindowAdapter(Context context,
			List<Node> list) {
		super();
		this.con = context;
		this.mInflater = LayoutInflater.from(con);
		this.list = list;
	}

	public int getCount() {
		// TODO Auto-generated method stub
		return list.size();
	}

	public Object getItem(int position) {
		// TODO Auto-generated method stub
		return list.get(position);
	}

	public long getItemId(int position) {
		// TODO Auto-generated method stub
		return position;
	}

	public View getView(int position, View convertView, ViewGroup parent) {
		// TODO Auto-generated method stub
//		Map<String, Object> map = (Map<String, Object>) getItem(position);
		CommViewHolder holder = null;

		if (convertView == null) {

			holder = new CommViewHolder();

			convertView = mInflater.inflate(
					R.layout.comm_list_popupwindow_item, null);

			holder.comm_list_dialog_item_text = (TextView) convertView
					.findViewById(R.id.comm_list_popupwindow_item_text);

			convertView.setTag(holder);

		}

		else {
			holder = (CommViewHolder) convertView.getTag();

		}
		Node n = list.get(position);
		holder.comm_list_dialog_item_text.setText(n.getText());
		return convertView;
	}

	static class CommViewHolder {

		TextView comm_list_dialog_item_text;

	}

}
